'''
Created on Oct 23, 2009

@author: kage
'''

from configobj import ConfigObj
import os , sys

class Startup():
    def __init__(self,file,folder):
        self.__file = file
        self.__folder = folder
        if(not os.path.exists(file)):
            f = open(file,"w")
            f.close()
            self.appConfig = ConfigObj(file)
            self.defaultConfigGen()
        else:
            self.appConfig = ConfigObj(file)
    
    def saveConfig(self, dataDict):
        self.appConfig.filename = self.__file
        self.appConfig['config'] = dataDict
        try:
            self.appConfig.write()
        except:
            print 'could not save settings file'
            
    def defaultConfigGen(self):
        toolsDir = os.path.join(self.__folder,"resources/tools")
        config = {}
        config['mkvMergePath'] = os.path.abspath(os.path.join(toolsDir, "mkvtoolnix/mkvmerge.exe")).replace('\\','/')
        config['mkvExtractPath'] = os.path.abspath(os.path.join(toolsDir, "mkvtoolnix/mkvextract.exe")).replace('\\','/')
        config['mediaInfoPath'] = os.path.abspath(os.path.join(toolsDir, "mediainfo/MediaInfo.exe")).replace('\\','/')
        config['templatePath'] = os.path.abspath(os.path.join(toolsDir, "mediainfo/template.txt")).replace('\\','/')
        config['inputFolder'] = './'
        config['outputFolder'] = './'
        config['title'] = ''
        config['priority'] = 'normal'
        config['logFile'] = os.path.abspath('../../log.txt').replace('\\','/')
        self.saveConfig(config)
